package com.changgou.file.service.impl;

import com.changgou.file.service.HeadService;
import com.changgou.user.config.TokenDecode;
import com.changgou.user.dao.UserMapper;
import com.changgou.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Map;

/**
 * HeadServiceImpl  TODO
 * 13418  computer
 *
 * @author zhougang
 * @date 2020/4/26 16:27
 */
@Service
public class HeadServiceImpl implements HeadService {

    @Autowired
    private TokenDecode tokenDecode;

    @Autowired
    private UserMapper userMapper;

    @Override
    public void add(String url) {
        Map<String, String> userInfo = tokenDecode.getUserInfo();
        String username = userInfo.get("username");

        User user = new User();
        user.setHeadPic(url);
        user.setUsername(username);

        Example example=new Example(User.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("username", username);
        userMapper.updateByExampleSelective(user, example);
    }
}
